package com.internal.Search.server;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.internal.Internalhibernate.client.MlLicenses;
import com.internal.Internalhibernate.client.SecUsers;
import com.internal.Internalhibernate.server.dao.MlLicensesDAO;
import com.internal.Internalhibernate.server.dao.SecUsersDAO;
import com.internal.Search.client.ProSuggestion;
import com.internal.Search.client.SearchService;
import com.internal.SharedModule.client.MLLicensesSearchBean;
import com.internal.SharedModule.server.CloneServerUtil;

public class SearchServiceImpl extends RemoteServiceServlet implements SearchService {

	@Override
	public ProSuggestion getProSuggest(SuggestOracle.Request req) throws Exception {
		ProSuggestion proSuggestion=SearchServerUtil.getProSuggest(req);
		return proSuggestion;
	}

	@Override
	public List<SecUsers> getSecUsers() throws Exception {
		SecUsersDAO secUsersDAO=new SecUsersDAO();
		List<SecUsers> secUsers=secUsersDAO.findAll();
		List<SecUsers> secUsers2=new ArrayList<SecUsers>();
		for (int i = 0; i <secUsers.size(); i++) {
			SecUsers secUsers3=new SecUsers();
			secUsers3.setUserId(secUsers.get(i).getUserId());
			secUsers3.setUserName(secUsers.get(i).getUserName());
			
			secUsers2.add(secUsers3);
		}
		return secUsers2;
	}

	@Override
	public List<MLLicensesSearchBean> getMLLicensesSearch(int licenNumberFrom)
			throws Exception {
		MlLicensesDAO mlLicensesDAO=new MlLicensesDAO();
		List<MlLicenses> mlLicenses=mlLicensesDAO.search(licenNumberFrom);
		
		return CloneServerUtil.getMLLicensesSearchBean(mlLicenses);
	}
}
